<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>栏目列表</title>
	<hdjs />
	<js file='__PUBLIC__/js/mod.base.js' />
	<css file="__PUBLIC__/Css/mod.base.css" />
</head>
<body>

	<form action="{:U('Category/update_order')}" method="post" class='hd-form'>
		<div class="hd-menu-list">
			<ul>
				<li class='active'>
					<a href="javascript:;" >栏目列表</a>
				</li>
				<li>
					<a href="{:U('Category/add')}">添加顶级栏目</a>
				</li>
				<li>
					<a href="{:U('Category/update_cache')}">更新栏目缓存</a>
				</li>
			</ul>
		</div>
		<table class="hd-table hd-table-list hd-form">
			<thead>
				<tr>
					<td class="hd-w30">
						<input type="checkbox" class="select_all"/>
					</td>
					<td class="hd-w30">CID</td>
					<td class="hd-w50">排序</td>
					<td>栏目名称</td>
					<td class="hd-w100">类型</td>
					<td class="hd-w100">模型</td>
					<td class="hd-w180">操作</td>
				</tr>
			</thead>
			<if condition='$data'>
				<foreach name='data' item='v'>
					<tr <if condition="$v['pid'] eq 0">class="top"</if>
					>
					<td>
						<input type="checkbox" name="cid[{$v.cid}]" value="{$v.cid}"/>
					</td>
					<td>{$v.cid}</td>
					<td>
						<input type="text" class="hd-w30" value="{$v.sort}" name="list_order[{$v.cid}]"/>
					</td>
					<td>
						<if condition="$v['pid'] eq 0 && Data::hasChild(S('category'),$v['cid'])">
							<img src="__PUBLIC__/Img/contract.gif" action="2" class="explodeCategory"/>
						</if>
						<if condition="$v['pid'] eq 0"> <strong>{$v._name}</strong>
							<else/>
							{$v._name}
						</if>
					</td>
					<td>{$v.type}</td>
					<td>{$v.model}</td>
					<td>
						<!-- <a href="" target="_blank">访问</a>
					<span class="line">|</span>
					-->
					<a href="{:U('Category/add',array('pid'=>
						$v['cid']))}">
								添加子栏目
					</a>
					<span class="line">|</span>
					<a href="{:U('Category/edit',array('cid'=>
						$v['cid']))}">
								修改
					</a>
					<span class="line">|</span>
					<a href="javascript:var del='{:U('Category/del',array('cid'=>
						$v['cid']))}';hd_modal_confirm('确认删除吗？',del)">
								删除
					</a>
				</td>
			</tr>
		</foreach>
		<else/>
		<tr>
			<td colspan="7">没有找到符合的记录</td>
		</tr>
	</if>
</table>

</form>

<div class="hd-position-bottom">
<input type="button" class="hd-btn hd-btn-xm" onclick="select_all(1)" value='全选'/>
<input type="button" class="hd-btn hd-btn-xm" onclick="select_all(0)" value='反选'/>
<input type="button" class="hd-btn hd-btn-xm" onclick="update_order()" value="更改排序"/>
</div>
<script>
 	//展开栏目
	$(".explodeCategory").click(function () {
	    var action = parseInt($(this).attr("action"));
	    var tr = $(this).parents('tr').eq(0);
	    switch (action) {
	        case 1://展示
	            $(tr).nextUntil('.top').show();
	            $(this).attr('action', 2);
	            $(this).attr('src', "__PUBLIC__/Img/contract.gif");
	            break;
	        case 2://收缩
	            $(tr).nextUntil('.top').hide();
	            $(this).attr('action', 1);
	            $(this).attr('src', "__PUBLIC__/Img/explode.gif");
	            break;
	    }
	})
	//关闭栏目子栏目（隐藏子栏目）
	$(".explodeCategory").trigger('click');
	//全部收起子栏目
	function explodeCategory() {
	    $(".explodeCategory").each(function (i) {
	        $(this).trigger('click');
	    })
	}
//更新排序
function update_order() {
    //栏目检测
    if ($("input[type='checkbox']:checked").length == 0) {
        alert('没有栏目用于排序');
        return false;
    }
  	$('form').submit();
}
//点击input表单实现 全选或反选
$(function () {
    //全选
    $("input.select_all").click(function () {
        $("[type='checkbox']").attr("checked",$(this).attr('checked')=='checked');
    })
})
//全选复选框
function select_all(state){
	if(state==1){
		$("[type='checkbox']").attr("checked",state);
	}else{
		$("[type='checkbox']").attr("checked",function(){return !$(this).attr('checked')});
	}
}

</script>
</body>
</html>